import numpy as np
import pandas as pd

# 加载并预处理数据
fdata = pd.read_csv('tips.csv')
fdata.rename(columns=({'total_bill':'消费总额','tip':'小费','sex':'性别','smoker':'是否抽烟',
                       'day':'星期','time':'聚餐时间段','size':'人数'}),inplace=True)
fdata['人均消费'] = round(fdata['消费总额']/fdata['人数'])

# 分析小费与各因素的关系
gender_tip = fdata.groupby('性别')['小费'].mean()
smoker_tip = fdata.groupby('是否抽烟')['小费'].mean()
time_tip = fdata.groupby('聚餐时间段')['小费'].mean()
day_tip = fdata.groupby('星期')['小费'].mean()



# 数据映射字典
gender_map = {0: 'Female', 1: 'Male'}
smoker_map = {0: 'No', 1: 'Yes'}
day_map = {0: 'Sun', 1: 'Mon', 2: 'Tue', 3: 'Wed', 4: 'Thu', 5: 'Fri', 6: 'Sat'}
time_map = {0: 'Lunch', 1: 'Dinner'}

# 反向映射字典，用于将英文转换为中文
gender_map_cn = {'Female': 'Female', 'Male': 'Male'}  # 假设数据中已经是中文
smoker_map_cn = {'No': 'No', 'Yes': 'Yes'}  # 假设数据中已经是中文
day_map_cn = {'Sun': 'Sun', 'Mon': 'Mon', 'Tue': 'Tue', 'Wed': 'Wed', 
              'Thu': 'Thu', 'Fri': 'Fri', 'Sat': 'Sat'}  # 假设数据中已经是中文
time_map_cn = {'Lunch': 'Lunch', 'Dinner': 'Dinner'}  # 假设数据中已经是中文



# 直接在主程序中进行预测逻辑
input_str = input()

try:
    # 解析输入
    gender, smoker, day, time, total_bill = input_str.split()
    gender = int(gender)
    smoker = int(smoker)
    day = int(day)
    time = int(time)
    total_bill = float(total_bill)
    
    # 映射到文本
    gender_text = gender_map[gender]
    smoker_text = smoker_map[smoker]
    day_text = day_map[day]
    time_text = time_map[time]
    
    # 转换为中文（如果需要）
    gender_text_cn = gender_map_cn[gender_text]
    smoker_text_cn = smoker_map_cn[smoker_text]
    day_text_cn = day_map_cn[day_text]
    time_text_cn = time_map_cn[time_text]
    
    # 过滤数据
    filtered_data = fdata[(fdata['性别'] == gender_text_cn) & 
                         (fdata['是否抽烟'] == smoker_text_cn) & 
                         (fdata['星期'] == day_text_cn) & 
                         (fdata['聚餐时间段'] == time_text_cn)]
    
    # 计算预测值
    if len(filtered_data) > 0:
        tip_ratio = (filtered_data['小费'] / filtered_data['消费总额']).mean()
        predicted_tip = round(tip_ratio * total_bill, 2)
        print(predicted_tip)  # 移除汉字，只保留数值
    else:
        # 如果没有匹配的数据，使用整体平均比率
        overall_tip_ratio = (fdata['小费'] / fdata['消费总额']).mean()
        predicted_tip = round(overall_tip_ratio * total_bill, 2)
        print(predicted_tip)  # 移除汉字，只保留数值
        
except ValueError:
    print("输入格式错误，请输入5个用空格分隔的值")
except Exception as e:
    print(f"发生错误: {str(e)}")
